package com.bawei.work_manager;

import android.content.Context;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.work.Data;
import androidx.work.Worker;
import androidx.work.WorkerParameters;

public class MyWork extends Worker {
    public MyWork(@NonNull Context context, @NonNull WorkerParameters workerParams) {
        super(context, workerParams);
    }

    @NonNull
    @Override
    public Result doWork() {
        //获得输入参数
        String username = getInputData().getString("username");
        int age = getInputData().getInt("age",0);
        Log.d("ytx", "doWork: "+username+":"+age);
        //任务完成后返回数据
        Data data = new Data.Builder()
                .putString("info", "用户名为" + username + "年龄为" + age)
                .build();
        return Result.success(data);//retry重试
    }
}
